fix(ffi): free transaction byte buffers correctly#749
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors FFI transaction buffer memory management to use a hidden length prefix. Transaction serialization now allocates a buffer prefixed with a ChangesFFI Transaction Buffer Memory Management
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@key-wallet-ffi/FFI_API.md`:
- Around line 1308-1311: The docs for the build-and-sign transaction function
refer to a parameter named `fee_rate` but the actual function signature uses
`fee_per_kb`; update all occurrences of `fee_rate` in the function description
and the Safety section to `fee_per_kb` (including the parameter list and
explanatory text) so the documentation matches the FFI signature, then
regenerate FFI_API.md to pick up the corrected source docs; reference the
documented function's parameter `fee_per_kb` and the Safety section entries for
`fee_rate` to locate and replace the mismatched names.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 32e6f687-4825-4656-87a3-c169bd9cad5c
📒 Files selected for processing (3)
key-wallet-ffi/FFI_API.mdkey-wallet-ffi/src/transaction.rskey-wallet-ffi/src/transaction_tests.rs
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #749 +/- ##
==========================================
+ Coverage 71.89% 71.91% +0.02%
==========================================
Files 320 320
Lines 69473 69465 -8
==========================================
+ Hits 49947 49957 +10
+ Misses 19526 19508 -18
|
Transaction-building FFI functions (`wallet_build_and_sign_transaction`, `wallet_build_and_sign_asset_lock_transaction`) hand back the serialized transaction as `Vec<u8>` -> `Box<[u8]>` -> `Box::into_raw(...) as *mut u8`. The previous `transaction_bytes_free(*mut u8)` then reconstructed `Box<u8>`, which is the wrong allocation layout for a boxed slice and is undefined behavior. Take the original length back from the caller and reconstruct the boxed slice via `Box::from_raw(slice_from_raw_parts_mut(ptr, len))`. Null remains a no-op. Update the safety docs on both builders and on `transaction_bytes_free` itself, refresh `FFI_API.md`, and add focused unit tests covering null free, freeing a `Box<[u8]>` with the matching length, and the empty-slice case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Checked the current head after the CodeRabbit retry: |
|
✅ Actions performedReview triggered.
|
Fix transaction byte buffer freeing
Summary
transaction_bytes_freeC ABI.function can reconstruct and drop the original boxed slice layout safely.
Validation
cargo test -p key-wallet-ffi transaction_bytes_free --libpython3 contrib/verify_ffi.pygit diff --checknpx markdownlint-cli2 /tmp/pr-body.md